import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
	public static int[][] bubbleSort(int[][] score) {
		int temp = 0;
		
		for(int i = 0; i < score.length - 1; i++) {
			for(int j = 0; j < score.length - 1 - i; j++) {
				if(score[j][1] < score[j + 1][1]) {
					for(int k = 0; k < score[i].length; k++) {
						temp = score[j][k];
						score[j][k] = score[j + 1][k];
						score[j + 1][k] = temp;
					}
				}
				else if(score[j][1] == score[j + 1][1]) {
					if(score[j][2] < score[j + 1][2]) {
						for(int k = 0; k < score[i].length; k++) {
							temp = score[j][k];
							score[j][k] = score[j + 1][k];
							score[j + 1][k] = temp;
						}
					}
				}
			}
		}
		return score;
	}
	public static String getSort(int[][] score) {
		String result = "";
		
		for(int i = 0; i < score.length; i++) {
			for(int j = 0; j < score[i].length; j++) {
				result += score[i][j];
				if(j < score[i].length - 1)
					result += " ";
			}
			result += "\n";
		}
		return result;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder output;
		String input;
		String[] spInput;
		int people;
		int[][] score;
		
		while((input = br.readLine()) != null) {
			people = Integer.parseInt(input);
			
			score = new int[people][3];
			
			for(int n = 0; n < people; n++) {
				input = br.readLine();
				spInput = input.split(" ");
				for(int cur = 0; cur < score[n].length; cur++)
					score[n][cur] = Integer.parseInt(spInput[cur]);
			}
			
			score = bubbleSort(score);
			
			output = new StringBuilder(getSort(score));
			
			System.out.print(output);
		}
	}
}